package com.kpmg.datalake.common.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kpmg.datalake.common.enums.UseOrDelEnum;
import com.kpmg.datalake.common.service.IComSystemParamsService;
import com.kpmg.datalake.db.dao.ComSystemParamsMapper;
import com.kpmg.datalake.db.model.ComSystemParams;
import org.apache.commons.lang3.StringUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统参数设置 服务实现类
 * </p>
 *
 * @author azhao6
 * @since 2018-08-17
 */
@Service
public class ComSystemParamsServiceImpl extends
    ServiceImpl<ComSystemParamsMapper, ComSystemParams> implements IComSystemParamsService {

  @Override
  @Cacheable(value = "systemParam", key = "#cspCode", unless = "#result == null")
  public String getSystemParamsByCode(String cspCode, String defaultValue) {
    String cspValue;
    ComSystemParams comSystemParams = new ComSystemParams();
    comSystemParams.setCspCode(cspCode);
    comSystemParams.setDelInd(UseOrDelEnum.USE.getIntCode());
    comSystemParams = baseMapper.selectOne(comSystemParams);
    if (comSystemParams != null && StringUtils.isNotBlank(comSystemParams.getCspCode())) {
      cspValue = comSystemParams.getCspValue();
    } else {
      cspValue = defaultValue;
    }
    return cspValue;
  }

  @Override
  public String getSystemParamsByCode(String cspCode) {
    return ((ComSystemParamsServiceImpl) AopContext.currentProxy())
        .getSystemParamsByCode(cspCode, null);
  }
}
